GNTTABOP_map_grant_ref returns error status and handle as
authorkaf24@firebug.cl.cam.ac.uk <kaf24@firebug.cl.cam.ac.uk>
Wed, 30 Nov 2005 16:24:27 +0000 (17:24 +0100)
committerkaf24@firebug.cl.cam.ac.uk <kaf24@firebug.cl.cam.ac.uk>
Wed, 30 Nov 2005 16:24:27 +0000 (17:24 +0100)
separate fields. Update callers for new interface. Also
use int16_t as standard error code type on all public
interfaces.

Signed-off-by: Keir Fraser <keir@xensource.com>
19 files changed:
linux-2.6-xen-sparse/drivers/xen/blkback/blkback.c
linux-2.6-xen-sparse/drivers/xen/blkback/common.h
linux-2.6-xen-sparse/drivers/xen/blkback/interface.c
linux-2.6-xen-sparse/drivers/xen/blktap/blktap.c
linux-2.6-xen-sparse/drivers/xen/blktap/common.h
linux-2.6-xen-sparse/drivers/xen/blktap/interface.c
linux-2.6-xen-sparse/drivers/xen/netback/common.h
linux-2.6-xen-sparse/drivers/xen/netback/interface.c
linux-2.6-xen-sparse/drivers/xen/netback/netback.c
linux-2.6-xen-sparse/drivers/xen/tpmback/common.h
linux-2.6-xen-sparse/drivers/xen/tpmback/interface.c
linux-2.6-xen-sparse/drivers/xen/tpmback/tpmback.c
tools/libxc/xc_domain.c
tools/libxc/xc_gnttab.c
tools/libxc/xenctrl.h
xen/common/grant_table.c
xen/include/public/dom0_ops.h
xen/include/public/grant_table.h
xen/include/public/io/blkif.h

index fe478fe336a128e6b4170cc407341eaee9abe23d..586ce79d986835dca8ae236220ac1d71b9ce7abd 100644 (file)
@@ -88,10 +88,10 @@ static inline void flush_plugged_queue(void)
  * handle returned must be used to unmap the frame. This is needed to
  * drop the ref count on the frame.
  */
-static u16 pending_grant_handles[MMAP_PAGES];
+static grant_handle_t pending_grant_handles[MMAP_PAGES];
 #define pending_handle(_idx, _i) \
     (pending_grant_handles[((_idx) * BLKIF_MAX_SEGMENTS_PER_REQUEST) + (_i)])
-#define BLKBACK_INVALID_HANDLE (0xFFFF)
+#define BLKBACK_INVALID_HANDLE (~0)
 
 #ifdef CONFIG_XEN_BLKDEV_TAP_BE
 /*
@@ -114,7 +114,7 @@ static void fast_flush_area(int idx, int nr_pages)
 {
        struct gnttab_unmap_grant_ref unmap[BLKIF_MAX_SEGMENTS_PER_REQUEST];
        unsigned int i, invcount = 0;
-       u16 handle;
+       grant_handle_t handle;
        int ret;
 
        for (i = 0; i < nr_pages; i++) {
@@ -381,7 +381,7 @@ static void dispatch_rw_block_io(blkif_t *blkif, blkif_request_t *req)
        BUG_ON(ret);
 
        for (i = 0; i < nseg; i++) {
-               if (likely(map[i].handle >= 0)) {
+               if (likely(map[i].status == 0)) {
                        pending_handle(pending_idx, i) = map[i].handle;
 #ifdef __ia64__
                        MMAP_VADDR(pending_idx,i) = gnttab_map_vaddr(map[i]);
index 96eafda2fec94ea382f64f8a66ebc9791771d235..0926ed0731d09ab472ae60ff82c600f429baec48 100644 (file)
@@ -66,8 +66,8 @@ typedef struct blkif_st {
 
        struct work_struct free_work;
 
-       u16         shmem_handle;
-       grant_ref_t shmem_ref;
+       grant_handle_t shmem_handle;
+       grant_ref_t    shmem_ref;
 } blkif_t;
 
 blkif_t *alloc_blkif(domid_t domid);
index 900b48271958f3e8aabd69d44259e8a1e68ae00a..15474a3205cbb23e87faafb6cb84083fd31bb389 100644 (file)
@@ -43,9 +43,9 @@ static int map_frontend_page(blkif_t *blkif, unsigned long shared_page)
        unlock_vm_area(blkif->blk_ring_area);
        BUG_ON(ret);
 
-       if (op.handle < 0) {
+       if (op.status) {
                DPRINTK(" Grant table operation failure !\n");
-               return op.handle;
+               return op.status;
        }
 
        blkif->shmem_ref = shared_page;
index aa0bdef432da67ee6c8703afe10051062a238c9c..f4c80f22b4014aacfddbe356b629e211d45d0ec2 100644 (file)
@@ -177,8 +177,8 @@ extern inline domid_t ID_TO_DOM(unsigned long id)
  */
 struct grant_handle_pair
 {
-       u16  kernel;
-       u16  user;
+       grant_handle_t kernel;
+       grant_handle_t user;
 };
 static struct grant_handle_pair pending_grant_handles[MMAP_PAGES];
 #define pending_handle(_idx, _i) \
@@ -755,17 +755,17 @@ static void dispatch_rw_block_io(blkif_t *blkif, blkif_request_t *req)
                uvaddr = MMAP_VADDR(user_vstart, pending_idx, i/2);
                kvaddr = MMAP_VADDR(mmap_vstart, pending_idx, i/2);
 
-               if (unlikely(map[i].handle < 0)) {
+               if (unlikely(map[i].status)) {
                        DPRINTK("Error on kernel grant mapping (%d)\n",
-                               map[i].handle);
-                       ret = map[i].handle;
+                               map[i].status);
+                       ret = map[i].status;
                        cancel = 1;
                }
 
-               if (unlikely(map[i+1].handle < 0)) {
+               if (unlikely(map[i+1].status)) {
                        DPRINTK("Error on user grant mapping (%d)\n",
-                               map[i+1].handle);
-                       ret = map[i+1].handle;
+                               map[i+1].status);
+                       ret = map[i+1].status;
                        cancel = 1;
                }
 
index 38fa80b55790449477f4743d4aec4718d37edceb..9571b057e140597bed442a85fe1c2bb808fa47e0 100644 (file)
@@ -64,7 +64,7 @@ typedef struct blkif_st {
 
        struct work_struct free_work;
 
-       u16              shmem_handle;
+       grant_handle_t   shmem_handle;
        grant_ref_t      shmem_ref;
 } blkif_t;
 
index 8627c1a4887e7da45c84b66f9e29a10c568956cb..58f30b0cfd56ad1dece93890d09e80ee67ce6286 100644 (file)
@@ -43,9 +43,9 @@ static int map_frontend_page(blkif_t *blkif, unsigned long shared_page)
        unlock_vm_area(blkif->blk_ring_area);
        BUG_ON(ret);
 
-       if (op.handle < 0) {
+       if (op.status) {
                DPRINTK(" Grant table operation failure !\n");
-               return op.handle;
+               return op.status;
        }
 
        blkif->shmem_ref    = shared_page;
index 5150cb8844432b47e7b00d6daee5864754032771..e1c5bd204f1eee0f7a32cdf4006ba210aea77b4c 100644 (file)
@@ -45,9 +45,9 @@ typedef struct netif_st {
        u8               fe_dev_addr[6];
 
        /* Physical parameters of the comms window. */
-       u16              tx_shmem_handle;
+       grant_handle_t   tx_shmem_handle;
        grant_ref_t      tx_shmem_ref; 
-       u16              rx_shmem_handle;
+       grant_handle_t   rx_shmem_handle;
        grant_ref_t      rx_shmem_ref; 
        unsigned int     evtchn;
        unsigned int     irq;
index 2cd235b2228f9729f6f7c3cc5cdc4f6862e6b66e..f4682750cb4c84b155aa8939b40271d2c6ec1012 100644 (file)
@@ -127,9 +127,9 @@ static int map_frontend_pages(
        unlock_vm_area(netif->comms_area);
        BUG_ON(ret);
 
-       if (op.handle < 0) { 
+       if (op.status) { 
                DPRINTK(" Gnttab failure mapping tx_ring_ref!\n");
-               return op.handle;
+               return op.status;
        }
 
        netif->tx_shmem_ref    = tx_ring_ref;
@@ -145,9 +145,9 @@ static int map_frontend_pages(
        unlock_vm_area(netif->comms_area);
        BUG_ON(ret);
 
-       if (op.handle < 0) { 
+       if (op.status) {
                DPRINTK(" Gnttab failure mapping rx_ring_ref!\n");
-               return op.handle;
+               return op.status;
        }
 
        netif->rx_shmem_ref    = rx_ring_ref;
index 2941119f6bc5b910877031dee21b19f1f1065fe6..0440aa43427c7275c6e603cc873750e2a511f200 100644 (file)
@@ -68,7 +68,7 @@ static PEND_RING_IDX dealloc_prod, dealloc_cons;
 
 static struct sk_buff_head tx_queue;
 
-static u16 grant_tx_ref[MAX_PENDING_REQS];
+static grant_handle_t grant_tx_handle[MAX_PENDING_REQS];
 static gnttab_unmap_grant_ref_t tx_unmap_ops[MAX_PENDING_REQS];
 static gnttab_map_grant_ref_t tx_map_ops[MAX_PENDING_REQS];
 
@@ -412,7 +412,7 @@ inline static void net_tx_action_dealloc(void)
                pending_idx = dealloc_ring[MASK_PEND_IDX(dc++)];
                gop->host_addr    = MMAP_VADDR(pending_idx);
                gop->dev_bus_addr = 0;
-               gop->handle       = grant_tx_ref[pending_idx];
+               gop->handle       = grant_tx_handle[pending_idx];
                gop++;
        }
        ret = HYPERVISOR_grant_table_op(
@@ -592,7 +592,7 @@ static void net_tx_action(unsigned long unused)
                       sizeof(txreq));
 
                /* Check the remap error code. */
-               if (unlikely(mop->handle < 0)) {
+               if (unlikely(mop->status)) {
                        printk(KERN_ALERT "#### netback grant fails\n");
                        make_tx_response(netif, txreq.id, NETIF_RSP_ERROR);
                        netif_put(netif);
@@ -605,7 +605,7 @@ static void net_tx_action(unsigned long unused)
                set_phys_to_machine(
                        __pa(MMAP_VADDR(pending_idx)) >> PAGE_SHIFT,
                        FOREIGN_FRAME(mop->dev_bus_addr >> PAGE_SHIFT));
-               grant_tx_ref[pending_idx] = mop->handle;
+               grant_tx_handle[pending_idx] = mop->handle;
 
                data_len = (txreq.size > PKT_PROT_LEN) ?
                        PKT_PROT_LEN : txreq.size;
index e12d25a1dd7ecb0409e6c11caaca189721b5f0f9..231f28bdb66581f89e43ddc3e9ec471c3847b2b1 100644 (file)
@@ -54,7 +54,7 @@ typedef struct tpmif_st {
 
        struct work_struct work;
 
-       u16 shmem_handle;
+       grant_handle_t shmem_handle;
        grant_ref_t shmem_ref;
 } tpmif_t;
 
index df33db9bfeaf9418566fbb412e03875481eed98f..c43fd0d72bbff2646845fd5f5d042909c42e4b07 100644 (file)
@@ -91,9 +91,9 @@ map_frontend_page(tpmif_t *tpmif, unsigned long shared_page)
        unlock_vm_area(tpmif->tx_area);
        BUG_ON(ret);
 
-       if (op.handle < 0) {
+       if (op.status) {
                DPRINTK(" Grant table operation failure !\n");
-               return op.handle;
+               return op.status;
        }
 
        tpmif->shmem_ref = shared_page;
index dd14f6087cd03bbe501086bef24dc0af931f3d67..8667c8d2fbe9b3007f41b6f4dfca75fbc7d47854 100644 (file)
@@ -249,7 +249,7 @@ _packet_write(struct packet *pak,
         * and send it to the front end.
         */
        tpmif_t *tpmif = pak->tpmif;
-       u16 handle;
+       grant_handle_t handle;
        int rc = 0;
        unsigned int i = 0;
        unsigned int offset = 0;
@@ -290,7 +290,7 @@ _packet_write(struct packet *pak,
 
                handle = map_op.handle;
 
-               if (map_op.handle < 0) {
+               if (map_op.status) {
                        DPRINTK(" Grant table operation failure !\n");
                        return 0;
                }
@@ -427,7 +427,7 @@ packet_read_shmem(struct packet *pak,
        u32 i = (last_read / PAGE_SIZE);
        u32 pg_offset = last_read & (PAGE_SIZE - 1);
        u32 to_copy;
-       u16 handle;
+       grant_handle_t handle;
 
        tpmif_tx_request_t *tx;
        tx = &tpmif->tx->ring[0].req;
@@ -455,7 +455,7 @@ packet_read_shmem(struct packet *pak,
                        BUG();
                }
 
-               if (map_op.handle < 0) {
+               if (map_op.status) {
                        DPRINTK(" Grant table operation failure !\n");
                        return -EFAULT;
                }
index 062006094d31eb98eb47447103b950484a4130f2..8cba15893debc5843d2f5fc6fc24276392eabac0 100644 (file)
@@ -365,9 +365,9 @@ int xc_domain_get_vcpu_info(int xc_handle,
 
 int xc_domain_ioport_permission(int xc_handle,
                                 uint32_t domid,
-                                uint16_t first_port,
-                                uint16_t nr_ports,
-                                uint16_t allow_access)
+                                uint32_t first_port,
+                                uint32_t nr_ports,
+                                uint32_t allow_access)
 {
     DECLARE_DOM0_OP;
 
index 54fb40e6e142dba86944c152325c71d6aecb124c..76b7b141c9eeccc7128e15809a5069d2ac0ef1ba 100644 (file)
@@ -42,9 +42,10 @@ do_gnttab_op(int xc_handle,
 int xc_gnttab_map_grant_ref(int         xc_handle,
                             uint64_t    host_virt_addr,
                             uint32_t    dom,
-                            uint16_t    ref,
+                            grant_ref_t ref,
                             uint16_t    flags,
-                            int16_t    *handle,
+                            int16_t    *status,
+                            grant_handle_t *handle,
                             uint64_t   *dev_bus_addr)
 {
     struct gnttab_map_grant_ref op;
@@ -58,6 +59,7 @@ int xc_gnttab_map_grant_ref(int         xc_handle,
     if ( (rc = do_gnttab_op(xc_handle, GNTTABOP_map_grant_ref,
                             &op, 1)) == 0 )
     {
+        *status         = op.status;
         *handle         = op.handle;
         *dev_bus_addr   = op.dev_bus_addr;
     }
@@ -69,7 +71,7 @@ int xc_gnttab_map_grant_ref(int         xc_handle,
 int xc_gnttab_unmap_grant_ref(int       xc_handle,
                               uint64_t  host_virt_addr,
                               uint64_t  dev_bus_addr,
-                              uint16_t  handle,
+                              grant_handle_t handle,
                               int16_t  *status)
 {
     struct gnttab_unmap_grant_ref op;
index 8afd5b01b29e3d48c3f50ea780dcab50a99843e7..d12ac4993ff777010ba97a392dde121115ade76c 100644 (file)
@@ -13,6 +13,7 @@
 #include <sys/ptrace.h>
 #include <xen/xen.h>
 #include <xen/dom0_ops.h>
+#include <xen/grant_table.h>
 #include <xen/version.h>
 #include <xen/event_channel.h>
 #include <xen/sched.h>
@@ -374,9 +375,9 @@ int xc_domain_memory_decrease_reservation(int xc_handle,
 
 int xc_domain_ioport_permission(int xc_handle,
                                 uint32_t domid,
-                                uint16_t first_port,
-                                uint16_t nr_ports,
-                                uint16_t allow_access);
+                                uint32_t first_port,
+                                uint32_t nr_ports,
+                                uint32_t allow_access);
 
 unsigned long xc_make_page_below_4G(int xc_handle, uint32_t domid, 
                                    unsigned long mfn);
@@ -475,15 +476,16 @@ int xc_grant_interface_close(int xc_handle);
 int xc_gnttab_map_grant_ref(int      xc_handle,
                             uint64_t host_virt_addr,
                             uint32_t dom,
-                            uint16_t ref,
+                            grant_ref_t ref,
                             uint16_t flags,
-                            int16_t *handle,
+                            int16_t *status,
+                            grant_handle_t *handle,
                             uint64_t *dev_bus_addr);
 
 int xc_gnttab_unmap_grant_ref(int  xc_handle,
                               uint64_t  host_virt_addr,
                               uint64_t  dev_bus_addr,
-                              uint16_t  handle,
+                              grant_handle_t handle,
                               int16_t *status);
 
 int xc_gnttab_setup_table(int        xc_handle,
index 46b16e0dafc69c99539910ba737ff232ec921c50..5d4955196b583622039dfa2ca52f5e59117f29d4 100644 (file)
@@ -114,13 +114,13 @@ __gnttab_map_grant_ref(
                    (GNTMAP_device_map|GNTMAP_host_map)) == 0) )
     {
         DPRINTK("Bad ref (%d) or flags (%x).\n", ref, dev_hst_ro_flags);
-        (void)__put_user(GNTST_bad_gntref, &uop->handle);
+        (void)__put_user(GNTST_bad_gntref, &uop->status);
         return GNTST_bad_gntref;
     }
 
     if ( acm_pre_grant_map_ref(dom) )
     {
-        (void)__put_user(GNTST_permission_denied, &uop->handle);
+        (void)__put_user(GNTST_permission_denied, &uop->status);
         return GNTST_permission_denied;
     }
 
@@ -130,7 +130,7 @@ __gnttab_map_grant_ref(
         if ( rd != NULL )
             put_domain(rd);
         DPRINTK("Could not find domain %d\n", dom);
-        (void)__put_user(GNTST_bad_domain, &uop->handle);
+        (void)__put_user(GNTST_bad_domain, &uop->status);
         return GNTST_bad_domain;
     }
 
@@ -145,7 +145,7 @@ __gnttab_map_grant_ref(
         {
             put_domain(rd);
             DPRINTK("Maptrack table is at maximum size.\n");
-            (void)__put_user(GNTST_no_device_space, &uop->handle);
+            (void)__put_user(GNTST_no_device_space, &uop->status);
             return GNTST_no_device_space;
         }
 
@@ -155,7 +155,7 @@ __gnttab_map_grant_ref(
         {
             put_domain(rd);
             DPRINTK("No more map handles available.\n");
-            (void)__put_user(GNTST_no_device_space, &uop->handle);
+            (void)__put_user(GNTST_no_device_space, &uop->status);
             return GNTST_no_device_space;
         }
 
@@ -370,6 +370,7 @@ __gnttab_map_grant_ref(
 
     (void)__put_user((u64)frame << PAGE_SHIFT, &uop->dev_bus_addr);
     (void)__put_user(handle, &uop->handle);
+    (void)__put_user(GNTST_okay, &uop->status);
 
     put_domain(rd);
     return rc;
@@ -377,7 +378,7 @@ __gnttab_map_grant_ref(
 
  unlock_out:
     spin_unlock(&rd->grant_table->lock);
-    (void)__put_user(rc, &uop->handle);
+    (void)__put_user(rc, &uop->status);
     put_maptrack_handle(ld->grant_table, handle);
     return rc;
 }
@@ -400,7 +401,7 @@ __gnttab_unmap_grant_ref(
 {
     domid_t          dom;
     grant_ref_t      ref;
-    u16              handle;
+    grant_handle_t   handle;
     struct domain   *ld, *rd;
     active_grant_entry_t *act;
     grant_entry_t   *sha;
@@ -957,7 +958,7 @@ gnttab_release_mappings(
     grant_table_t        *gt = d->grant_table;
     grant_mapping_t      *map;
     grant_ref_t           ref;
-    u16                   handle;
+    grant_handle_t        handle;
     struct domain        *rd;
     active_grant_entry_t *act;
     grant_entry_t        *sha;
index 4ff18fcd0615aa72a325efdf8d96f4ca7b955d01..5627a441e4743384d67ec9b7d4608f82e19b0b85 100644 (file)
@@ -19,7 +19,7 @@
  * This makes sure that old versions of dom0 tools will stop working in a
  * well-defined way (rather than crashing the machine, for instance).
  */
-#define DOM0_INTERFACE_VERSION   0xAAAA1013
+#define DOM0_INTERFACE_VERSION   0xAAAA1014
 
 /************************************************************************/
 
index c5d0f0bc4ffb7d80698e515b9a4bba778b003a4b..166e4ae327d6f646a14cbbcec1560936029b7102 100644 (file)
@@ -133,6 +133,11 @@ typedef struct grant_entry {
  */
 typedef uint32_t grant_ref_t;
 
+/*
+ * Handle to track a mapping created via a grant reference.
+ */
+typedef uint32_t grant_handle_t;
+
 /*
  * GNTTABOP_map_grant_ref: Map the grant entry (<dom>,<ref>) for access
  * by devices and/or host CPUs. If successful, <handle> is a tracking number
@@ -154,11 +159,12 @@ typedef uint32_t grant_ref_t;
 typedef struct gnttab_map_grant_ref {
     /* IN parameters. */
     uint64_t host_addr;
-    domid_t  dom;
-    grant_ref_t ref;
     uint32_t flags;               /* GNTMAP_* */
+    grant_ref_t ref;
+    domid_t  dom;
     /* OUT parameters. */
-    int32_t  handle;              /* +ve: handle; -ve: GNTST_* */
+    int16_t  status;              /* GNTST_* */
+    grant_handle_t handle;
     uint64_t dev_bus_addr;
 } gnttab_map_grant_ref_t;
 
@@ -178,9 +184,9 @@ typedef struct gnttab_unmap_grant_ref {
     /* IN parameters. */
     uint64_t host_addr;
     uint64_t dev_bus_addr;
-    uint32_t handle;
+    grant_handle_t handle;
     /* OUT parameters. */
-    int32_t  status;              /* GNTST_* */
+    int16_t  status;              /* GNTST_* */
 } gnttab_unmap_grant_ref_t;
 
 /*
@@ -198,7 +204,7 @@ typedef struct gnttab_setup_table {
     domid_t  dom;
     uint32_t nr_frames;
     /* OUT parameters. */
-    int32_t  status;              /* GNTST_* */
+    int16_t  status;              /* GNTST_* */
     unsigned long *frame_list;
 } gnttab_setup_table_t;
 
@@ -211,7 +217,7 @@ typedef struct gnttab_dump_table {
     /* IN parameters. */
     domid_t dom;
     /* OUT parameters. */
-    int32_t status;               /* GNTST_* */
+    int16_t status;               /* GNTST_* */
 } gnttab_dump_table_t;
 
 /*
@@ -229,7 +235,7 @@ typedef struct {
     domid_t       domid;
     grant_ref_t   ref;
     /* OUT parameters. */
-    int32_t       status;
+    int16_t       status;
 } gnttab_transfer_t;
 
 /*
index 3a9bf2e7bb83f944ef112ac5c4998327ce7d86cd..9a91ef82f996e2f61969e63d683cdc807fc8ca9d 100644 (file)
@@ -43,7 +43,7 @@ typedef struct blkif_request {
 typedef struct blkif_response {
     uint64_t        id;              /* copied from request */
     uint8_t         operation;       /* copied from request */
-    int32_t         status;          /* BLKIF_RSP_???       */
+    int16_t         status;          /* BLKIF_RSP_???       */
 } blkif_response_t;
 
 #define BLKIF_RSP_ERROR  -1 /* non-specific 'error' */